package domain.dao;

import java.util.Iterator;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import domain.Action;

public class ActionsDao extends AbstractDao {

	public ActionsDao()
	{
		super();
	}
	
	private final static String HQL_LOAD_ACTIONS = "from Action";
	  
	public void prepareActions() {
	    try {
	      begin();
	      Query query = getSession().createQuery(HQL_LOAD_ACTIONS);
	      List<Action> actions = (List<Action>) query.list();
	      for (Action action : actions) {
          System.out.println("Action: " + action.getName() + " (" + action.getArgs() + ") {" + action.getScript() + "}");
        }
//	      Iterator i = query.iterate();
//	      while(i.hasNext())
//	      {
//	    	  Object[] row 	= (Object[])i.next();
//	    	  String name	= (String)row[0];
//	    	  String args	= (String)row[1];
//	    	  String script	= (String)row[2];
//	    	  System.out.println("Action: " + name + " (" + args + ") {" + script + "}");
//	      }
	      commit();
	      //return user;
	    } catch (HibernateException e) {
	      rollback();
	    }
	    //return null;
	  }
}
